<template>
  <div class="login">
    <div class="logo">
      <img class="logo-img" src="../assets/logo.png" alt />
    </div>
    <el-form class="form" :model="userInfo" :rules="formRules">
      <el-form-item prop="username">
        <el-input placeholder="请输入用户名" prefix-icon="el-icon-user-solid" v-model="userInfo.username"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password"  placeholder="请输入密码" v-model="userInfo.password" prefix-icon="el-icon-s-goods"></el-input>
      </el-form-item>
    </el-form>
    <el-row class="btn">
      <el-button type="success" @click="loginBtn">登录</el-button>
      <el-button type="danger">重置</el-button>
    </el-row>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      userInfo: {
        username: "zhangkaishuang",
        password: "woaigaoshuang"
      },
      formRules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" }
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }]
      }
    };
  },
  methods: {
    loginBtn() {
      this.$axios.post("/api/isLogin", this.userInfo).then(res => {
        if (!res.data.data.verifySuccess) {
          this.$message({
            message: "登陆失败",
            type: "error"
          })
        } else {
          console.log(res.data.data.userInfo.token);
          sessionStorage.setItem("token", res.data.data.userInfo.token);
          this.$message({
            message: "登陆成功",
            type: "success"
          })
          this.$router.push('/home')
        }
      })
    }
  }
};
</script>

<style>
.login {
  width: 100%;
  height: 100%;
  background: white;
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: center;
}
.logo {
  width: 1.8rem;
  height: 1.2rem;
  position: absolute;
  top: 1.8rem;
}
.logo-img {
  width: 1.8rem;
  height: 1.2rem;
}
.form {
  position: absolute;
  top: 3.3rem;
  width: 3rem;
}
.btn {
  top: 4.7rem;
  left: 0.46rem;
}
</style>